
select t.par_id,t.fat_anno,t.fat_num,t.FAT_DT, t.SOG_RAGSOC ,t.SOG_CODFIS,t.SOG_PARIVA,
t.FAT_TELEDESSPE,t.FAT_ELETDESSTASPE,t.FAT_INDNUMSPE,decode (ec.tmov_id ,107,(nvl(scr_imp_d,0)-nvl(scr_imp_a,0)),t.TOT_FAT) tot_fat,
ec.scr_imp_d DARE,
CASE WHEN (SELECT ec1.scr_imp_a FROM V_SCRITTURADEST_EC EC1 WHERE EC.PAR_ID=EC1.PAR_ID AND EC1.TMOV_ID=3) IS not NULL  THEN 
                        (SELECT ec1.scr_imp_a FROM V_SCRITTURADEST_EC EC1 WHERE EC.PAR_ID=EC1.PAR_ID AND EC1.TMOV_ID=3) ELSE ec.scr_imp_A END AVERE,
DECODE (EC.ISS_ID_PARTITA,602,'Aperta',603,'Chiusa',null) stato_partita
from v_fatturat t,
V_SCRITTURADEST_EC ec
where t.par_id=ec.par_id
and ec.tmov_id  in (100,107) 
and t.FAT_ANNO<>2013
;

select * from imp_fatturat where fat_anno=2008 and fat_num  in (3267) and tfat_idold = 8003275;

select distinct tmov_id,tmov_des,tscr_id,tscr_des from V_SCRITTURADEST_EC_tmp;


select par_id from V_fatturat where par_id = 1876 and fat_anno=2008 and fat_num =3267;

select *
from V_SCRITTURADEST_EC_tmp where  par_id = 1916; 

select *
from V_SCRITTURADEST_EC_tmp where mov_nota like '%3267%' and  mov_nota like '%2008%';

